package com.seguriapp.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.seguriapp.R;
import com.seguriapp.dialogs.GenericDialog;
import com.seguriapp.util.AppPrefences;

/**
 * TODO(pjohnson): Insert description
 * 
 * @author Pablo Johnson (pablo.88j@gmail.com)
 */
public class MainActivity extends android.support.v4.app.FragmentActivity {

	private MainActivity mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mContext = this;
		final AppPrefences msp = new AppPrefences(this);
		if (!msp.isWelcomeDialogShowed()) {
			GenericDialog.createDialog(this, R.string.welcome_dialog_title,
					R.string.welcome_dialog_message,
					GenericDialog.WELCOME_DIALOG).show();
			msp.setWelcomeDialogShowed(true);
		}

		setRelationInIcons();

	}

	public void setRelationInIcons() {
		final ImageButton btnEntitiy = (ImageButton) findViewById(R.id.btnBuscarComisaria);
		btnEntitiy.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(final View v) {
				final Intent intent = new Intent();
				intent.setClass(mContext, EntityTypeActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.aparecer_desde_derecha,
						R.anim.desaparecer_fading);

			}
		});

		final ImageButton btnComplaint = (ImageButton) findViewById(R.id.btnRegComplaint);
		btnComplaint.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(final View v) {
				final Intent intent = new Intent();
				intent.setClass(mContext, ComplaintActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.aparecer_desde_derecha,
						R.anim.desaparecer_fading);
			}
		});

		final ImageButton btnSignal = (ImageButton) findViewById(R.id.btnSos);
		btnSignal.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(final View v) {
				final Intent intent = new Intent();
				intent.setClass(mContext, SignalActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.aparecer_desde_derecha,
						R.anim.desaparecer_fading);
			}
		});

		final ImageButton btnCrime = (ImageButton) findViewById(R.id.btnActividadCriminal);
		btnCrime.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(final View v) {
				final Intent intent = new Intent();
				intent.setClass(mContext, CrimeMapFragmentActivity.class);
				intent.putExtra("dataSource", "crime");
				startActivity(intent);
				overridePendingTransition(R.anim.aparecer_desde_derecha,
						R.anim.desaparecer_fading);
			}
		});

		final ImageButton btnTramites = (ImageButton) findViewById(R.id.btnTramites);
		btnTramites.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(final View v) {
				final Intent intent = new Intent();
				intent.setClass(mContext, TramitesActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.aparecer_desde_derecha,
						R.anim.desaparecer_fading);
			}
		});
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		final MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.settings_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.setting_menu:
			final Intent intent = new Intent();
			intent.setClass(mContext, SettingsActivity.class);
			startActivity(intent);
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
